//让字符串成为回文串的最少插入次数
//测试链接：https://leetcode.cn/problems/minimum-insertion-steps-to-make-a-string-palindrome/
public class MinInsertions {
    public int minInsertions(String s) {
        int n = s.length();
        int[][] dp = new int[n][n]; // 创建 dp 表
        for (int i = n - 1; i >= 0; i--)
            for (int j = i + 1; j < n; j++)
                if (s.charAt(i) == s.charAt(j))
                    dp[i][j] = dp[i + 1][j - 1];
                else
                    dp[i][j] = Math.min(dp[i][j - 1], dp[i + 1][j]) + 1;
        return dp[0][n - 1];
    }
}
